import java.util.Arrays;

public class quiksortAi {
    public static void main(String[] args) {
        int[] arr = {10, 7, 8, 4, 3,1, 5};
        System.out.println("排序前:");
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.asList("11,111".split(","),-1).toString());
        quickSort(arr, 0, arr.length - 1);


        System.out.println("\n排序后:");
        System.out.println(Arrays.toString(arr));
    }
    //递归调用
    public static void quickSort(int[] arr, int low, int high) {
        if (low < high) {
            int pi = partition(arr, low, high);
            quickSort(arr, low, pi-1);
            quickSort(arr, pi + 1, high);
        }
    }
    //交换与基点位置偏移
    public static int partition(int[] arr, int low, int high) {
        int pivot = arr[high];
        //基点最终指针 初始值为low
        int i = low ;

        for (int j = low; j < high; j++) {
            if (arr[j] < pivot) {
                swap(arr, i, j);
                i++;
            }
        }
        swap(arr, i , high);
        return i;
    }

    public static void swap(int[] arr, int i, int j) {
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }

}
